package com.gewu.pm.bean;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品分类数据模型
 */
public class CategoryTypeBean {
    
    /** 分类ID */
    private String id;
    /** 分类名称 */
    private String name;
    /** 是否有子分类 */
    private boolean hasChildren;
    /** 子分类列表 */
    private List<CategoryTypeBean> children;
    /** 是否展开 */
    private boolean isExpanded;
    /** 是否选中 */
    private boolean isSelected;
    /** 是否为子分类 */
    private boolean isChild;

    public CategoryTypeBean(String id, String name) {
        this.id = id;
        this.name = name;
        this.hasChildren = false;
        this.children = new ArrayList<>();
        this.isExpanded = false;
        this.isSelected = false;
        this.isChild = false;
    }

    public CategoryTypeBean(String id, String name, boolean isChild) {
        this(id, name);
        this.isChild = isChild;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isHasChildren() {
        return hasChildren;
    }

    public void setHasChildren(boolean hasChildren) {
        this.hasChildren = hasChildren;
    }

    public List<CategoryTypeBean> getChildren() {
        return children;
    }

    public void setChildren(List<CategoryTypeBean> children) {
        this.children = children;
        this.hasChildren = children != null && !children.isEmpty();
    }

    public void addChild(CategoryTypeBean child) {
        if (children == null) {
            children = new ArrayList<>();
        }
        child.setChild(true);
        children.add(child);
        this.hasChildren = true;
    }

    public boolean isExpanded() {
        return isExpanded;
    }

    public void setExpanded(boolean expanded) {
        isExpanded = expanded;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }

    public boolean isChild() {
        return isChild;
    }

    public void setChild(boolean child) {
        isChild = child;
    }
}

